<?php
class ModelPromotionKeyword extends Model {
	
	public function addKeywordIn($keyword) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "key_words_in SET keyword = '" . $keyword . 
			"', add_time = NOW(), lang_id = '" . (int)$this->config->get('config_language_id') . "'");
	}

	public function getKeywordsForHome($limit) {
				
		$keyword_data = $this->cache->get('promotion.keyword.home.' . (int)$this->config->get('config_language_id') . $limit);

		if (!$keyword_data) {
			$query = $this->db->query("SELECT id, keyword FROM " . DB_PREFIX . "key_words WHERE status = 1 AND show_type = 2 " . 
				"AND lang_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY click_num DESC LIMIT " . (int)$limit);
			$keyword_data = $query->rows;
			$this->cache->set('promotion.keyword.home.' . (int)$this->config->get('config_language_id') . $limit, $keyword_data);
		}
		
		return $keyword_data;
	}
	
	public function getKeywordsForSearch($keyword, $limit) {
				
		$keyword_data = $this->cache->get('promotion.keyword.search.' . (int)$this->config->get('config_language_id') . $keyword . $limit);

		if (!$keyword_data) {
			$query = $this->db->query("SELECT id, keyword FROM " . DB_PREFIX . "key_words WHERE keyword like '" . $keyword . 
				"%' AND lang_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY click_num DESC LIMIT " . (int)$limit);
			$keyword_data = $query->rows;
			$this->cache->set('promotion.keyword.search.' . (int)$this->config->get('config_language_id') . $keyword . $limit, $keyword_data);
		}
		
		return $keyword_data;
	}
}
?>